package online.cmagic.actionType.myiterator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangsc
 * @date: 2020年04月15日 20:11
 * @since JDK 1.8
 */
public class MyCollection {
    private List<String> list =new ArrayList<String>();

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public void add(String o){
        this.list.add(o);
    }

    public MyIterator newIterator(){
        return new MyImplIterator();
    }

    private class MyImplIterator implements MyIterator{

        private int cursor=0;

        public boolean hasNext() {
            return cursor<list.size();
        }

        public String next() {
            String res="";
            if (cursor<list.size()){
                res = list.get(cursor);
            }
            cursor++;
            return res;
        }
    }

}
